package org.aurora.module.user.infra.repository;

import org.aurora.module.user.domain.entity.Role;
import org.aurora.module.user.domain.repository.RoleRepository;
import org.aurora.module.user.infra.dal.mysql.converter.RoleConverter;
import org.aurora.module.user.infra.dal.mysql.mapper.RoleMapper;
import org.springframework.stereotype.Component;

/**
 * RoleRepositoryImpl
 * <pre>
 * description: 角色仓储实现
 * create date: 2025-03-22 19:45:21
 * </pre>
 *
 * @author cao.yong
 */
@Component
public class RoleRepositoryImpl implements RoleRepository {

    private final RoleMapper roleMapper;

    public RoleRepositoryImpl(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }

    @Override
    public void save(Role entity) {
        this.roleMapper.insert(RoleConverter.INSTANCE.convert(entity));
    }

    @Override
    public void delete(Long id) {
        this.roleMapper.deleteById(id);
    }

    @Override
    public void delete(Role entity) {
        this.roleMapper.delete(RoleConverter.INSTANCE.convert(entity));
    }

    @Override
    public void update(Role entity) {
        this.roleMapper.update(RoleConverter.INSTANCE.convert(entity));
    }

    @Override
    public Role findById(Long id) {
        return RoleConverter.INSTANCE.convert(this.roleMapper.selectOneById(id));
    }
}
